package com.ncloud.act.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ncloud.act.common.ActDataHelper;
import com.ncloud.act.entity.BsCycle;
import com.ncloud.act.mapper.BsCycleMapper;
import com.ncloud.act.mapper.ChnlDepositMapper;
import com.ncloud.act.mapper.ChnlSalesMapper;
import com.ncloud.act.service.ChnlDepositService;
import com.ncloud.common.exception.UserException;

@Service
public class ChnlDepositServiceImpl implements ChnlDepositService{
	private static final Logger logger = LogManager.getLogger(ChnlDepositServiceImpl.class);
	/*@Resource
	private ChnlSalesMapper chnlSalesMapper;*/
	@Resource
	private BsCycleMapper bsCycleMapper;
	@Resource
	private ChnlDepositMapper chnlDepositMapper;
	@Override
	public JSONArray getChnlDepositInfo(JSONObject json) {
		Integer user_id = 0;
		//Long chnl_id = 0l;
		if(json.containsKey("userID"))
		{
			user_id=json.getInteger("userID");
		}else{
			throw new UserException("4000", "没有用户编码");
		}
		//user_id=33l;//test
		/*List<ChnlSales> ChnlSales = chnlSalesMapper.getChnlSalesByUserID(user_id);
		if(ChnlSales!=null && ChnlSales.size()>0){
			chnl_id=ChnlSales.get(0).getChnl_id();
		}*/
		//已出账最大账期
		List<BsCycle> maxOpenCycle = bsCycleMapper.getMaxOpenCycle();
		Integer bill_cycle_id=maxOpenCycle.get(0).getCycle_id();
		List<JSONObject> chnlDepositInfo = chnlDepositMapper.getChnlDepositInfo(bill_cycle_id, user_id);
		
		JSONArray results=JSON.parseArray(JSON.toJSONString(chnlDepositInfo));
		ActDataHelper.div100(results, new String[] { "deposit_money","credit_value","balance","historybalance"});
		return results;
	}
}
